package jdbc.homework;

import jdbc.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class LoginDemo {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try(Connection conn = DBUtil.getConnection()) {
            String sql = "select * from user where username=? and password=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            System.out.println("请输入用户名:");
            String username = sc.next();
            System.out.println("请输入密码:");
            String password = sc.next();
            ps.setString(1,username);
            ps.setString(2,password);
            System.out.println(ps.executeQuery().next()?"登录成功":"登录失败");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
